package main

import (
	"encoding/json"
	"good/api/handler"
	"good/config"
	"good/consts"
	"good/inits"
	"good/internal/queue"
	"log"
)

func main() {
	config.InitViper()
	inits.InitMysql()
	inits.InitRedis()
	inits.InitRabbitMq()

	msgs := queue.PublishSub(consts.SEND_GROUP)

	forever := make(chan bool)
	//启用协程处理消息
	go func() {
		for d := range msgs {
			//消息逻辑处理，可以自行设计逻辑
			log.Printf("Received a message: %s", d.Body)

			for _, onlineConn := range handler.OnlineUser {
				var data string
				_ = json.Unmarshal(d.Body, &data)
				handler.WSRespSuccess(onlineConn, data)
			}
		}
	}()

	log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
	<-forever
}
